type RouteType = 'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab' | 'navigateBack';

interface NavigateOptions {
  url: string;
  type?: RouteType;
  success?: (res: UniApp.NavigateToSuccessOptions) => void;
  fail?: (err: any) => void;
  complete?: () => void;
}

/**
 * 路由跳转封装函数
 * @param options 跳转配置
 */
export function navigate(options: NavigateOptions): void {
  const { url, type = 'navigateTo', success, fail, complete } = options;

  switch (type) {
    case 'navigateTo':
      uni.navigateTo({ url, success, fail, complete });
      break;
    case 'redirectTo':
      uni.redirectTo({ url, success, fail, complete });
      break;
    case 'reLaunch':
      uni.reLaunch({ url, success, fail, complete });
      break;
    case 'switchTab':
      uni.switchTab({ url, success, fail, complete });
      break;
    case 'navigateBack':
      uni.navigateBack();
      break;
    default:
      console.error(`未知的路由类型: ${type}`);
  }
}
